package Mylist;

public class Mylist {
    public static void main(String[] args) {
        //选用合适的构造方法，用你学号前后各两名同学的学号创建四个结点
        //把上面四个节点连成一个没有头结点的单链表
        Node<Student> s1 = new Node<Student>(new Student("20165318", "孙晓暄"), null);
        Node<Student> s2 = new Node<Student>(new Student("20165317", "宁心宇"), s1);
        Node<Student> s3 = new Node<Student>(new Student("20165315", "阎含"), s2);
        Node<Student> s4 = new Node<Student>(new Student("20165314", "陈由章"), s3);
        Node<Student> Hd = new Node<Student>(new Student(), s4);
        Node<Student> pla = Hd.next;
        while (pla != null) {
            String str = pla.data.getId();
            System.out.println(str);
            pla = pla.getNext();
        }
        System.out.printf("\n");
        Node<Student> s5 = new Node<Student>(new Student("20165316","孙勖哲"),null);
        pla = Hd.next;
        while (pla != null) {
            String st = pla.data.getId();
            if(st.equals("20165315")){
                s5.next = pla.next;
                pla.next = s5;
            }
            pla = pla.next;
        }
        //把你自己插入到合适的位置（学号升序）
        /*s3.next = s5;
        s5.next = s2;*/
        //遍历单链表，打印每个结点的
        pla = Hd.next;
        while (pla != null) {
            String str = pla.data.getId();
            System.out.println(str);
            pla = pla.getNext();
        }
        System.out.printf("\n");
        pla = Hd.next;
        while (pla != null) {
            String st = pla.data.getId();
            if(st.equals("20165315")){
                pla.next = pla.next.next;
            }
            pla = pla.next;
        }
        //从链表中删除自己
        /*s3.next = s2;*/
        //遍历单链表，打印每个结点的
        pla = Hd.next;
        while (pla != null) {
            String str = pla.data.getId();
            System.out.println(str);
            pla = pla.getNext();
        }
    }
}
